home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Module: cspifadj.c - line adjustment functions for cspiff */
- /* */
- /* Programmer: George R. Woodside */
- /* */
- /* Date: October 25, 1986 */
- /* */
- /* Function: Perform alignment functions on program lines. */
- /* */
- /****************************************************************************/
-
- #include <stdio.h>
-
- extern int left; /* left column for comments */
- extern int right; /* right column for comments */
- extern int tab; /* step value for indentations */
- extern int align; /* number of steps to indent */
- extern int c_flag; /* continued comment line flag */
-
- /****************************************************************************/
- /* */
- /* Construct a solid line of asterisks, as a comment line. */
- /* */
- /****************************************************************************/
-
- comm_solid(out)
- char out[];
- {
- register int i = 0; /* pointer index */
- out[i++] = '/'; /* leading slash */
- while(i < right-1)
- out[i++] = '*'; /* pad the line */
- out[i++] = '/'; /* trailing slash */
- out[i] = '\0'; /* terminator */
- } /* end solid line */
-
- /****************************************************************************/
- /* */
- /* Construct a solid block of asterisks, from the current */
- /* indentation column to the right margin, as a comment line. */
- /* */
- /****************************************************************************/
-
- comm_block(out,in)
- char out[];
- char in[];
- {
- register int i= -1; /* pointer index */
-
- while(in[++i] != '*')
- out[i] = in[i]; /* copy up to block */
-
- while(i < right-1)
- out[i++] = '*'; /* pad the line */
- out[i++] = '/'; /* trailing slash */
- out[i] = '\0'; /* terminator */
- } /* end solid line */
-
- /****************************************************************************/
- /* */
- /* Adjust the comment line in 'in' to force the right edge to 'right' */
- /* if possible. If it is too long, allow it to extend past 'right'. */
- /* */
- /****************************************************************************/
-
- comm_fix(out,in)
- char out[];
- char in[];
- {
- register int i = -1;
- register int j;
-
- j = ecomm(in); /* find end of comment area */
-
- if( j == -1 ) /* if no end of comment, */
- {
- c_flag = 1; /* set continued comment flag */
- while(in[++i]) /* for the length of the line, */
- out[i] = in[i]; /* copy the comment */
- out[i] = '\0'; /* add the terminator */
- return(0); /* and get out */
- } /* end process unterminated comment */
-
- for( i=0; i<=j; i++ )
- out[i] = in[i]; /* copy significant portion of line */
-
- while(i < right-2)
- out[i++] = ' '; /* pad the line */
- out[i++] = '*'; /* trailing asterisk */
- out[i++] = '/'; /* trailing slash */
- out[i] = '\0'; /* terminator */
-
- } /* end comment fix */
-
- /****************************************************************************/
- /* */
- /* Adjust the comment line in 'in' to align the left edge with the */
- /* prior (unterminated) comment line. */
- /* */
- /****************************************************************************/
-
- comm_sync(out,in)
- char out[];
- char in[];
- {
- register int i = -1;
- register int j;
-
- while(in[++i]) /* for the length of the line, */
- out[i] = in[i]; /* copy the comment */
- out[i] = '\0'; /* add the terminator */
-
- j = ecomm(in); /* find end of comment area */
-
- if( j != -1 ) /* if comments end, */
- c_flag = 0; /* set off continued flag */
- } /* end comment fix */
-
- /****************************************************************************/
- /* */
- /* Adjust the start position of the code in 'in' to be aligned */
- /* 'align' steps of 'tab'. Return aligned code in 'out'. */
- /* */
- /****************************************************************************/
-
- code_left(out,in)
- char in[]; /* input line */
- char out[]; /* output line */
- {
- register int i;
- register int j = 0;
-
- for( i = 0; i < align*tab; i++)
- out[i] = ' '; /* pad to alignment position */
- out[i] = '\0'; /* add a terminator */
- while(in[j] == ' ') /* skip leading spaces */
- j++; /* but stay at first data byte */
- strcat(out,&in[j]); /* add text to pad */
- } /* end code_left */
-
- /****************************************************************************/
- /* */
- /* Align the comment portion of 'in' to fit from 'left' to right', */
- /* or as close as possible, then return it in 'out'. */
- /* */
- /****************************************************************************/
-
- comm_align(out,in)
- char in[]; /* input line */
- char out[]; /* output line */
- {
- register int i = 0; /* general purpose */
- register int j = 0; /* general purpose */
- register int flag = 0; /* loop trigger */
- register int dend = -1; /* end of data segment */
- register int cstart; /* start of comment */
- register int clen; /* length of comment segment */
- register int c; /* character image */
-
- /**************************************************************************/
- /* */
- /* First, copy code segment of line to output array. */
- /* Save the address of the second trailing space. */
- /* */
- /**************************************************************************/
-
- while( (flag == 0) && (c = in[i]) )
- {
- if(c == '"') /* if we hit a quote, */
- {
- out[i++] = c; /* copy the opening quote */
- while(( c = in[i] ) && (c != '"')) /* until end of quote or line */
- out[i++] = c; /* copy the quoted byte */
-
- } /* end quoted string */
-
- if( (c == '/') && (in[i+1] == '*') ) /* if we are at the start, */
- {
- flag = 1; /* got the comment */
- cstart = i; /* save start position */
- }
- else /* not at comment yet */
- {
- if(c != ' ')
- dend = i; /* save data byte address */
- out[i++] = c; /* copy the byte */
- } /* end not at comment yet */
- } /* end of line */
-
- if(flag == 0) /* did not locate comment */
- {
- out[i] = '\0'; /* insure terminated */
- return(0); /* end of line, no comment */
- }
-
- i = dend + 1; /* back up to data */
- flag = ecomm(in); /* find end of comment */
-
- if(flag == -1) /* if bad syntax, */
- return(0); /* give up on line. */
-
- clen = flag - cstart +1; /* compute comment length */
-
- if(dend < left) /* if data ends soon enough, */
- j = left; /* start at normal position. */
- else /* if data is too long, */
- j = dend+2; /* leave one space after it. */
-
- while(i < j)
- out[i++] = ' '; /* blank fill to comment location. */
-
- while(clen)
- {
- out[i++] = in[cstart++]; /* now copy comment */
- clen--; /* for whatever its length is */
- }
-
- do {
- out[i++] = ' '; /* insure at least one space */
- } while(i < right-2); /* pad to right edge */
-
- out[i++] = '*'; /* put in asterisk */
- out[i++] = '/'; /* and slash */
- out[i] = '\0'; /* and terminate */
- }
-
- /****************************************************************************/
- /* */
- /* Determine address of last data character in comment portion */
- /* of line. Skip trailing asterisk, slash, and white space. */
- /* Return index of last data character, or -1 if not found. */
- /* */
- /****************************************************************************/
-
- ecomm(line)
- char line[];
- {
- register int i;
- register int flag = 0;
-
- i = strlen(line) -1 ; /* find end of line */
-
- while( (flag == 0) && (i > 3) )
- {
- if( (line[i] == '/') && (line[i-1] == '*') )
- {
- flag = 1; /* got end of comment symbol */
- i-= 2; /* get behind asterisk */
- while( (i) && (line[i] == ' ') )
- i--; /* back up to data */
- }
- else
- i--; /* keep looking */
- }
- if(flag) /* if we found the end, */
- return(i); /* return it. */
- else /* if not, */
- return(-1); /* return not found flag. */
- }
-